<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../../pages/common/head.jsp" %>
<html>
<head>
    <title>通过商品名查询的商品显示的页面</title>
    <style>
        a {
            text-decoration: none;
        }

        #goodImg {
            width: 305px;
            height: 150px;
        }

    </style>
    <script type="text/javascript">
        $(function () {
            //给加入购物车绑定单击事件
            $(".addCart").click(function () {
                var username = $(this).attr("username");
                var GoodsId = $(this).attr("GoodsId");
                if (username == null || username == "") {
                    alert("加入购物车失败，请先登录!");
                } else {
                    location.href = "cartServlet?action=addItem&id=" + GoodsId;
                }
            })
        })
    </script>
</head>
<body>
<div style="width: 100%;height: 50px;
background-color: #2aabd2;
text-align: center;color: white;font-size: 26px;padding-top: 8px">
    海飞丝洗发护发用品销售系统
</div>
<div style="width: 100%;height: 50px;
background-color: rgba(34,212,239,0.71);font-size: 20px;padding: 8px">
    <c:if test="${empty sessionScope.user}">
        <a href="pages/user/regist.jsp"><span style="color:#d93535;">注册</span></a>
        <span style="color: white">|</span>
        <a href="pages/user/login.jsp"><span style="color:#d93535;">登录</span></a>
    </c:if>
    <c:if test="${not empty sessionScope.user}">
        <span style="color: #d93535">用户：${sessionScope.user.name}</span>
        <span style="color: #242222;font-size: 23px">|</span>
        <a href="pages/user/userCenter.jsp"><span style="color: #d93535">个人中心</span></a>
        <span style="color: #242222;font-size: 23px">|</span>
        <a href="user/userController?action=loginOut"><span style="color: #d93535">退出登录</span></a>
        <a href="pages/cart/cart.jsp"><span
                style="color:#d93535;float: right;padding-right: 10px;padding-top: 2px">购物车</span></a>
        <c:if test="${sessionScope.user.name == 'admin'}">
            <span style="color: #242222;font-size: 23px;float: right;padding-right: 12px">|</span>
            <a href="pages/admin/manager.jsp"><span
                    style="color:#d93535;float: right;padding-right: 14px;padding-top: 2px">后台管理</span></a>
        </c:if>
    </c:if>
</div>
<div>
    <form method="post" action="admin/goodsController?action=queryGoodsByName">
        <span style="color: #68abba;font-size: 20px">按商品名查询商品</span>
        <input type="text" name="name" placeholder="请输入您想要的商品名"/>
        <input class="btn btn-success" type="submit" value="点击查询"/>
    </form>
    <form method="post" action="admin/goodsController?action=queryGoodsByPrice">
        <span style="color: #68abba;font-size: 20px">按价格查询商品</span>
        <input type="text" name="minPrice" placeholder="请输入商品最低价"/> --
        <input type="text" name="maxPrice" placeholder="请输入商品最高价"/>
        <input class="btn btn-success" type="submit" value="点击查询"/>
    </form>
    <a href="index.jsp"><span style="color: #d93535;font-size: 20px">返回商城首页</span></a>
</div>
<br/>
<div>
    <c:forEach var="i" items="${requestScope.nameGoods}">
        <div style="width: 20%;display: inline-block;
    height: 300px;margin-top: 10px;margin-left: 50px;
    color: #66afe9;font-size: 20px;text-align: center">
            <img src="${i.img}" id="goodImg"/>
            <div>${i.name}</div>
            <div>价格：${i.price}</div>
            <div>余量：${i.num}</div>
            <button GoodsId="${i.id}" username="${sessionScope.user.name}" class="addCart">
                加入购物车
            </button>
        </div>
    </c:forEach>
</div>

</body>
</html>

